/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Máté
 */
public class Composite implements IComposite { //megvalositja az IComposite interfeszt

    private List<IComposite> composites;    //IComposite-ot megvalostio objektumokat tarol

    public Composite() {    //konstruktor
        this.composites = new ArrayList<IComposite>();
    }

    public void addElement(IComposite element) {    //igy tudunk uj elemet beletenni
        this.composites.add(element);
    }

    public List<Port> getInputPorts() {
        List<Port> retVal = new ArrayList<Port>();

        for (IComposite current : composites) {
            if ((current instanceof Port) && !((Port) current).isOutput()) {
                retVal.add((Port) current);
            }
        }

        return retVal;
    }

    public List<Port> getOutputPorts() {
        List<Port> retVal = new ArrayList<Port>();

        for (IComposite current : composites) {
            if ((current instanceof Port) && ((Port) current).isOutput()) {
                retVal.add((Port) current);
            }
        }

        return retVal;
    }

    public Integer getInputPortCount() {
        Integer retVal = 0;

        for (IComposite current : composites) {
            if ((current instanceof Port) && !((Port) current).isOutput()) {
                retVal++;
            }
        }

        return retVal;
    }

    public Integer getOutputPortCount() {
        Integer retVal = 0;

        for (IComposite current : composites) {
            if ((current instanceof Port) && ((Port) current).isOutput()) {
                retVal++;
            }
        }

        return retVal;
    }

    public Boolean contains(IComposite composite) {
        return composites.contains(composite);
    }
}
